<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<view class="action" @tap="BackPage" v-if="isBack&&!isHome">
					<text class="cuIcon-back"></text>
					<text class="text-df">{{backText}}</text>
				</view>
				<view class="action" v-if="isBack&&isHome">
					<view class="navigation-bar-capsule"> 
						<text  @tap="BackPage" class="cuIcon-back"></text>
						<view style="width: 1rpx;height: 18px;border-right:1px solid rgba(255,255,255,.5)"></view>
						<text  @tap="HomePage" class="cuIcon-homefill"></text>
					</view>
				</view>
				<view class="action" @tap="CityPage" v-if="isCity">
					<text class="text-df">{{areaName}}</text>
					<text style="padding-left: 10rpx;" class="cuIcon-locationfill"></text>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<text style="font-size: 30rpx;" class="text-cut">{{title}}</text>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.$StatusBar,
				CustomBar: this.$CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar||0;
				var CustomBar= this.CustomBar||50;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		onReady() {
			this.StatusBar=this.$StatusBar
			this.CustomBar=this.$CustomBar
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			backText: {
				type: String,
				default: ''
			},
			isCity: {
				type: [Boolean, String],
				default: false 
			},
			areaName: {
				type: String,
				default: ''
			},
			title: {
				type: String,
				default: ''
			},
			isHome: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				// #ifdef H5
				let a = this.$Router.back(1)
				if (a == undefined) {
				//重新定向跳转页面
					this.$Router.replaceAll({ name:'home'})
				}
				// #endif
				// #ifndef H5
				this.$Router.back(1)
				// #endif
			},
			CityPage() {
				this.$emit('areaChange');
			},
			HomePage() {
				this.$Router.replaceAll({ name:'home'})
			}
		}
	}
</script>

<style lang="scss">
.navigation-bar-capsule{
	position: absolute;
		// height: 32px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		line-height: 28px;
		height: 28px;
		font-size: 16px;
		width: 70px;
		left: 10px;
		//background-color: rgba(255,255,255,.2);
		border-radius: 16px;
		border:0.5px solid rgba(255,255,255,.3);
		box-sizing: border-box;
		overflow: hidden;
	}

</style>

